<div class="row">
<div class="row">
    <div class="col">
        <?php echo CHtml::activeLabelEx($address,"[$belong]type"); ?>
        <?php echo CHtml::activeDropDownList($address, "[$belong]type", company_address::model()->type); ?>
    </div>
    <div class="col">
        <?php echo CHtml::activeLabelEx($address,"[$belong]postal"); ?>
        <?php echo CHtml::activeTextField($address,"[$belong]postal",array('size'=>10,'maxlength'=>20)); ?>
    </div>
</div>
    <div class="row">
<div class="col">
    <?php echo CHtml::activeLabelEx($address,"[$belong]country"); ?>
    <?php echo CHtml::activeTextField($address, "[$belong]country",array('size'=>40)); ?>
</div>
    </div>
<div class="row">
    <div class="col">
    <?php echo CHtml::activeLabelEx($address,"[$belong]address"); ?>
    <?php echo CHtml::activeTextArea($address,"[$belong]address",array('rows'=>3, 'cols'=>42)); ?>
    </div>
</div>
<div id="contacts">
<div class="row">
    <div class="col"><?php echo CHtml::label("Tel No.", 'telephone');?></div>
    <div class="col" id="telephone">
        <?php foreach($address->contacts as $i=>$item): if($item['type']<10): ?>
        <div>
            <?php echo CHtml::activeDropDownList($item, "[$belong]type", company_contacts::model()->teleType,array('name'=>"company_contacts[$belong][$i][type]")); ?>
            <?php echo CHtml::activeTextField($item,"[$belong]ref",array('size'=>25,'maxlength'=>35,'name'=>"company_contacts[$belong][$i][ref]")); ?>
        </div>
        <?php endif;  endforeach; ?>
    </div>
</div>
<div class="row">
    <div class="col"><?php echo CHtml::label("Fax No.", 'fax');?></div>
    <div class="col" id="fax">
        <?php foreach($address->contacts as $i=>$item): if($item['type']>9 && $item['type']<20): ?>
        <div>
            <?php echo CHtml::activeDropDownList($item, "[$belong]type[$i]", company_contacts::model()->faxType,array('name'=>"company_contacts[$belong][$i][type]")); ?>
            <?php echo CHtml::activeTextField($item,"[$belong]ref[$i]",array('size'=>25,'maxlength'=>35,'name'=>"company_contacts[$belong][$i][ref]")); ?>
        </div>
        <?php endif; endforeach; ?>
    </div>
</div>
</div>
        <?php if($belong == 0):?>
<div id="email">

<div class="row">
    <div class="col"><?php echo CHtml::label("Email", 'email');?></div>
    <div class="col" id="email">
    <?php foreach($address->email as $i=>$item): ?>
        <div>
            <?php echo CHtml::activeDropDownList($item, "[$belong]type[$i]", company_email::model()->emailType,array('name'=>"company_email[$belong][$i][type]")); ?>
            <?php echo CHtml::activeTextField($item,"[$belong]ref[$i]",array('size'=>25,'maxlength'=>35,'name'=>"company_email[$belong][$i][ref]")); ?>
        </div>
    <?php endforeach; ?></div>
</div>

</div>
        <?php endif; ?>
</div>
<?php
    $cs = Yii::app()->getClientScript();
    $contact = count($address->contacts)-1;
    $email = count($address->email)-1;
    $s =<<<EOD
        $('div#tabaddress').data('index',$belong);
        $('div#contacts').eq($belong).data('index',$contact);
        $('div#email').eq($belong).data('index',$email);
EOD;
    $cs->registerScript('registerIndex#'.$belong,$s);
?>